using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MyCinema
{
    public partial class ViewExcelForm : Form
    {
        string strCon = " Provider = Microsoft.Jet.OLEDB.4.0;Data Source={file};Extended Properties=Excel 8.0";
        string file;
        DataSet ds;

        public ViewExcelForm(string _title,string _file)
        {
            InitializeComponent();
            strCon = strCon.Replace("{file}", _file);
            file = _file;
            this.Text = _title;
        }

        private void ViewExcelForm_Load(object sender, EventArgs e)
        {
            try
            {
                OleDbConnection conn = new OleDbConnection(strCon);
                string sql = "select * from [Sheet1$]";
                conn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter(sql, strCon);
                ds = new DataSet();
                myCommand.Fill(ds, "[Sheet1$]");
                conn.Close();
                dgvTickets.DataMember = "[Sheet1$]";
                dgvTickets.DataSource = ds;
            }
            catch (Exception ex)
            {
                if (File.Exists(file))
                {
                    System.Diagnostics.Process.Start(file);
                }
                this.Close();
            }
        }
    }
}